<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %><%--
  Created by IntelliJ IDEA.
  User: 肖林
  Date: 2018/4/3
  Time: 16:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title> </title>
    <style type="text/css">
        table {
            border: 1px solid #000;
            border-collapse: collapse;
        }

        td, th {
            border: 1px solid #000;
            padding: 10px;
        }
    </style>
</head>
<body>
<table align="center">
    <thead>
    <tr>
        <td>id</td>
        <td >username</td>
        <td >password</td>
        <td>操作</td>
       <td>操作 </td>
        <td><a href="userAdd.jsp">添加</a></td>
    </tr>

    </thead>
    <tbody>

    <%
        class user{
            int id;
            String username;
            String password;

            public  user(int id, String username,String password)
            {
                this.id=id;
                this.username=username;
                this.password=password;
            }
        }

        List<user> list = new ArrayList<>();
        Connection connection=null;
        Statement statement= null;
        ResultSet resultSet=null;

        String sql="select * from t_user";
        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/javaweb_2018?serverTimezone=Asia/Shanghai",
                "root",
                "195122"
        );
        statement = connection.createStatement();

        resultSet = statement.executeQuery(sql);

        while(resultSet.next()){

            int id = resultSet.getInt(1);
            String username = resultSet.getString(2);
            String password = resultSet.getString(3);

            user user = new user(id, username, password);
            list.add(user);

        }
        resultSet.close();
        statement.close();
        connection.close();

        for (user user:list){
            out.write("<tr> <td>"+user.id+"</td> <td>"+user.username
                    +"</td> <td>"+user.password+"</td> " +
                    "<td><a href='delate.jsp?id="+user.id+"'>删除</a></td>"+
                    "<td><a href='user_reset.jsp?id="+user.id+"&usm="+user.username+"&psd="+user.password+"'> 修改</a></td></tr>");
        }
    %>
    </tbody>
</table>

</body>
</html>